﻿using System;
using System.Collections;
using System.Reflection;

namespace SimpleORM
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
    public sealed class DReaderAttribute : Attribute
    {
        #region Fields

        private object type;

        #endregion

        #region Properties

        public object Type
        {
            get { return type; }
        }

        #endregion

        #region Ctor

        public DReaderAttribute(object type)
        {
            this.type = type;
        }

        #endregion

        #region Methods

        public static Hashtable CreateReaders(Type type)
        {
            Hashtable ht = new Hashtable();

            MethodInfo[] listMethods = type.GetMethods(BindingFlags.Static |
                                                       BindingFlags.Public);

            foreach (MethodInfo mi in listMethods)
            {
                DReaderAttribute[] attrs = mi.GetAttributes<DReaderAttribute>();

                foreach (DReaderAttribute attr in attrs)
                {
                    if (ht.ContainsKey(attr.type))
                        continue;

                    ht.Add(attr.type, mi);
                }
            }

            return ht;
        }


        #endregion
    }
}